package com.whitedust.top10;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author A
 * @since 2025/11/1 12:19
 */

public class Top1 {
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.isEmpty()) return 0;
        Set<Character> hs = new HashSet<>();
        char[] c = s.toCharArray();
        int i = 0;
        int j = 1;
        hs.add(c[i]);
        int res = 1;
        while(j<s.length()){
            if(!hs.contains(c[j])){
                hs.add(c[j]);
                j++;
            }else{
                while(c[i]!=c[j]){
                    hs.remove(c[i]);
                    i++;
                }
                hs.remove(c[i]);
                i++;
            }
            res = Math.max(res,hs.size());
        }
        return res;
//        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
//        System.out.println(s);
//        Top1 a = new Top1();
//        int res = a.lengthOfLongestSubstring(s);
//        System.out.println(res);
    }


}